package org.thanos.demo.controller;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thanos.demo.utils.JasyptUtils;

import java.util.HashMap;
import java.util.Map;

@RestController
public class DemoController {

    @Value("${value}")
    private String value;

    @Value("${encryptor-value}")
    private String encryptorValue;

    @Autowired
    @Qualifier("jasyptStringEncryptor")
    private StringEncryptor stringEncryptor;

    /**
     * 从yml读取
     *
     * @return
     */
    @GetMapping("/yml")
    public Map<String, String> yml() {
        Map<String,String> result = new HashMap<>(2);
        result.put("value", value);
        result.put("encryptorValue", encryptorValue);
        return result;
    }

    /**
     * 从工具类读取
     *
     * @return
     */
    @GetMapping("/properties")
    public String properties() {
        return JasyptUtils.encryptPwd("demo", "123");
    }
}
